package com.wjb.xietong.server.topic;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.wjb.xietong.server.BaseResponseDataParse;
import com.wjb.xietong.server.HeaderInfoResponse;
import com.wjb.xietong.util.IDs;
import com.wjb.xietong.util.LogD;

public class GetZanPeopleListResponse extends BaseResponseDataParse {

	private static GetZanPeopleListResponse instance = null;
	private HeaderInfoResponse headerInfo = null;
	private List<ZanPeopleInfo> zanPeopleInfoList = null;

	private GetZanPeopleListResponse() {

	}

	public static synchronized GetZanPeopleListResponse instance() {
		if (null == instance) {
			instance = new GetZanPeopleListResponse();
		}
		return instance;
	}

	@Override
	public void initData() {
		setHeaderInfo(null);
		setZanPeopleInfoList(null);
	}

	@Override
	public boolean parseJsonObj(JSONObject response) {
		initData();

		if (null == response) {
			LogD.output("Exception: response is null");
			return false;
		}

		if (!checkRespCode(response)) {
			headerInfo = new HeaderInfoResponse();
			headerInfo.parseJsonObj(response);
			setHeaderInfo(headerInfo);
			return false;
		}

		if (response.has(IDs.ZAN_USER_MAP_LIST)) {
			JSONArray jsonArray = response.optJSONArray(IDs.ZAN_USER_MAP_LIST);
			if (null != jsonArray) {
				zanPeopleInfoList = new ArrayList<GetZanPeopleListResponse.ZanPeopleInfo>();
				for (int i = 0; i < jsonArray.length(); i++) {
					ZanPeopleInfo peopleInfo = new ZanPeopleInfo();
					JSONObject jsonObj = jsonArray.optJSONObject(i);
					if (jsonObj.has(IDs.USER_NAME2)) {
						peopleInfo
								.setUserName(jsonObj.optString(IDs.USER_NAME2));
					}
					if (jsonObj.has(IDs.USER_ID)) {
						peopleInfo.setUserId(jsonObj.optLong(IDs.USER_ID));
					}
					if (jsonObj.has(IDs.USER_FLAG)) {
						peopleInfo
								.setUserFlag(jsonObj.optString(IDs.USER_FLAG));
					}
					zanPeopleInfoList.add(peopleInfo);
				}
				setZanPeopleInfoList(zanPeopleInfoList);
			}
			return true;
		}
		return false;
	}

	public static class ZanPeopleInfo {
		private String userName = null;
		private long userId = 0l;
		private String userFlag = null;//头像url地址

		public String getUserName() {
			return userName;
		}

		public void setUserName(String userName) {
			this.userName = userName;
		}

		public long getUserId() {
			return userId;
		}

		public void setUserId(long userId) {
			this.userId = userId;
		}

		public String getUserFlag() {
			return userFlag;
		}

		public void setUserFlag(String userFlag) {
			this.userFlag = userFlag;
		}

	}

	public HeaderInfoResponse getHeaderInfo() {
		return headerInfo;
	}

	public void setHeaderInfo(HeaderInfoResponse headerInfo) {
		this.headerInfo = headerInfo;
	}

	public List<ZanPeopleInfo> getZanPeopleInfoList() {
		return zanPeopleInfoList;
	}

	public void setZanPeopleInfoList(List<ZanPeopleInfo> zanPeopleInfoList) {
		this.zanPeopleInfoList = zanPeopleInfoList;
	}

}
